/**
 * 系统全局参数设置js
 * date: 2010-12-9
 */

(function($){
	var SystemConfig = (function(){
		
		var articleListPageSize,articleDetailPageSize,discussPageSize,debug,recordClick;
		
		var initValue = function(){
			$.getJSON("/admin/config/sc_gSystemConfig.do", function(data){
				articleListPageSize.val(data.config.articleListPageSize);
				articleDetailPageSize.val(data.config.articleDetailPageSize);
				discussPageSize.val(data.config.discussPageSize);
				debug.filter("[value='"+data.config.debug+"']").attr("checked","true");
				recordClick.filter("[value='"+data.config.recordClick+"']").attr("checked","true");
			});					
		};
		var submitValue = function(){
			$.postJson({
				url: "/admin/config/sc_sSystemConfig.do",
				data: {
					"config.debug" : debug.filter("[checked='true']").val(),
					"config.recordClick" : recordClick.filter("[checked='true']").val(),
					"config.articleListPageSize" : articleListPageSize.val(),
					"config.articleDetailPageSize" : articleDetailPageSize.val(),
					"config.discussPageSize" : discussPageSize.val()
				},
				success: function(data){
					alert("修改成功！");
				}
			});
		};
		var checkParameter = function(){
			return true;
		};
		return {
			init : function(){
				articleListPageSize = $("#systemConfig input[name='config.articleListPageSize']");
				articleDetailPageSize = $("#systemConfig input[name='config.articleDetailPageSize']");
				discussPageSize = $("#systemConfig input[name='config.discussPageSize']");
				debug = $("#systemConfig input[name='config.debug']");
				recordClick = $("#systemConfig input[name='config.recordClick']");
				initValue();
			},
			check : function(){
				return checkParameter();
			},
			makeChange : function(){
				submitValue();
			}
		};
	})();
	
	$(document).ready(function(){
		SystemConfig.init();
		$("#sc-submit").click(function(){
			if(SystemConfig.check()){
				SystemConfig.makeChange();
			}
		});
	});
})(jQuery);